/*
 * Copyright (c) 2015, 张涛.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kymjs.themvp.presenter;

import com.kymjs.themvp.view.IDelegate;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Presenter base class for Fragment
 * Presenter层的实现基类
 *
 * @param <T> View delegate class type
 * @author kymjs (http://www.kymjs.com/) on 10/23/15.
 */
public abstract class FragmentPresenter<T extends IDelegate> extends AbilitySlice {
    /**
     * viewDelegate
     */
    public T viewDelegate;

    /**
     * onStart
     *
     * @param intent intent
     */
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        try {
            viewDelegate = getDelegateClass().newInstance();
        } catch (Exception e) {
            Logger.getLogger("theMvp").log(Level.WARNING, e.toString());
        }

        viewDelegate.create(this, null, false);
        setUIContent(viewDelegate.getRootView());
        viewDelegate.initWidget();
        bindEvenListener();
    }

    /**
     * onActive
     */
    @Override
    protected void onActive() {
        super.onActive();
    }

    /**
     * bindEvenListener
     */
    protected void bindEvenListener() {
    }


    /**
     * onStop
     */
    @Override
    protected void onStop() {
        super.onStop();
        viewDelegate = null;
    }

    /**
     * getDelegateClass
     *
     * @return Class
     */
    protected abstract Class<T> getDelegateClass();
}
